<?php
namespace ZHMVC\DB\MANAGER;
if (! isset($_SESSION)) {
    session_start();
}
include (dirname(dirname(__FILE__)) . "/zhconfig/Config.php");
include (ZH_PATH . DS . MANAGERFPATH . DS . 'islogin' . ZH);
$isp = new \ZHMVC\D\MANAGER\isPermission();
$isper = $isp->getPermission();
$_curlid = $isp->getCUrl();

include (ZH_PATH . DS . MANAGERFPATH . DS . 'top1' . ZH);
?>
<div class="wap-container">
	<nav class="breadcrumb" style="background-color:#fff;padding: 0 24px">
	系统设置
	<a class="btn btn-success radius f-r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a>
	</nav>
<!--/_header 作为公共模版分离出去-->
<?php 

$action=SafeRequest(getPGC('atcion'),0);

switch ($action)
{
    case "save":
        save();
        break;
    default:
        main();
}

function main()
{
    $data = D("zhmvc_master")->where("id='".$_SESSION['adminid']."' and username='".$_SESSION['adminname']."'")->getLinkOne("id,username,userpassword");
    $id=$data['id'];
    $username=$data['username'];
    $userpassword=$data['userpassword'];
?>
<article class="Hui-admin-content clearfix">
<div class="panel">
<div class="panel-body">
<form action="?atcion=save" id="form1" name="form1" method="post" class="form form-horizontal">

			<div class="row clearfix">
					<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>用户名：</label>
					<div class="form-controls col-xs-8 col-sm-9">
						<input type="text" name="username" class="input-text" placeholder="" value="<?php echo $username; ?>" />
					</div>
			</div>
			<div class="row clearfix">
					<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>旧密码：</label>
					<div class="form-controls col-xs-8 col-sm-9">
						<input type="text" id="olduserpassword" name="olduserpassword" class="input-text"
                 placeholder="请输入旧密码" value="" />
					</div>
			</div>
          	
            <div class="row clearfix">
					<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>新密码：</label>
					<div class="form-controls col-xs-8 col-sm-9">
						<input type="text" name="pwd" id="pwd" class="input-text"
                 		placeholder="请输入新密码" value="" />
					</div>
			</div>
            <div class="row clearfix">
					<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>再次输入新密码：</label>
					<div class="form-controls col-xs-8 col-sm-9">
						<input type="text" name="pwd2" id="pwd2" class="input-text"
                 placeholder="再次输入新密码" value="" />
					</div>
			</div>
            
            <div class="row clearfix">
					<div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
					<input type="hidden" name="id" value="<?php echo $_SESSION['adminid']; ?>"><input type="hidden" name="action" value="save"><input type="hidden" name="canshu" value="save">
						<input class="btn btn-primary radius" type="submit" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
					</div>
			</div>
</form>      
</div>
   </div>
</article>
</div>
<script type="text/javascript" src="/common/hui/lib/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="/common/hui/lib/layer/3.1.1/layer.js"></script>
<script type="text/javascript" src="/common/hui/static/h-ui/js/H-ui.js"></script>
</body>
</html>
<?php
}


function save()
{
    $conn=new \ZHMVC\D\DataBase();
    $id=$_SESSION['adminid'];
    $adminname=$_SESSION['adminname'];
    $olduserpassword=SafeRequest(getPGC('olduserpassword'),0);
    $pwd=SafeRequest(getPGC('pwd'),0);
    $pwd2=SafeRequest(getPGC('pwd2'),0);

    if($pwd!=$pwd2)
    {
       echo "<script>alert('对不起，两次输入的密码不一致');history.back();</script>";
       exit;
    }
    
    $sql = "select id from zhmvc_master where username='".$adminname."' and userpassword='".md5($olduserpassword)."' and id='".$id."'";
    $datas = $conn -> getSqlAll($sql);
    $rows = $conn -> getRowCount();
    if($rows==0)
    {
        echo "<script>alert('对不起，旧密码不正确');history.back();</script>";
        exit;
    }
    $sql="update zhmvc_master set userpassword='".md5($pwd)."' where id='".$id."'";
    //echo $sql;
    $conn -> SqlUpdate($sql);
    echo "<br />更新成功!";
}
?>
</div>
<?php 
include (ZH_PATH . DS . MANAGERFPATH . DS . 'foot' . ZH);
?>
</body>
</html>